package com.srv.servlet;

import junit.framework.TestCase;
import junit.framework.Assert;

/**
 * 这个是用来测试Json转换相关的类
 * @author Administrator
 *
 */
public class ResponseResultTestCase extends TestCase {
	/**
	 * 测试简单的场景
	 */
	public void testSimpleResult() { 
		ResponseResult rr = new ResponseResult();
		String expect = "{\"r\":\"ok\"}";		
        Assert.assertEquals(expect,rr.toJson());
        
        rr.theResult = ResponseResult.RESULT_OK;
        Assert.assertEquals(expect,rr.toJson());
        
        rr.theResult = ResponseResult.RESULT_FAIL;
        expect = "{\"r\":\"fail\"}";
        Assert.assertEquals(expect,rr.toJson());
    }
	public void testStringMessage() { 
		ResponseResult rr = new ResponseResult();
		String expect = "{\"r\":\"ok\",\"m\":\"this is string\"}";	
		rr.theMessageObj="this is string";
        Assert.assertEquals(expect,rr.toJson());
        
        rr.theResult = ResponseResult.RESULT_OK;
        Assert.assertEquals(expect,rr.toJson());
        
        rr.theResult = ResponseResult.RESULT_FAIL;
        expect = "{\"r\":\"fail\",\"m\":\"this is string\"}";
        Assert.assertEquals(expect,rr.toJson());
    }
	public void testStringArrayMessage() { 
		ResponseResult rr = new ResponseResult();
		String expect = "{\"r\":\"ok\",\"m\":[\"a\",\"b\",\"c\",\"d\"]}";	
		String[] ss={"a","b","c","d"};
		rr.theMessageObj= ss;		
        Assert.assertEquals(expect,rr.toJson());
        
        rr.theResult = ResponseResult.RESULT_OK;
        Assert.assertEquals(expect,rr.toJson());
       
    }
}